package br.mil.eb.pqrmnt7.scc.entity;

import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Access;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.AccessType;
import com.powerlogic.jcompany.commons.config.stereotypes.SPlcEntity;
import javax.persistence.Entity;

/**
 * Classe Concreta gerada a partir do assistente
 */
@SPlcEntity
@Entity
@Table(name = "MOTORISTA")
@SequenceGenerator(name = "SE_MOTORISTA", sequenceName = "SE_MOTORISTA")
@Access(AccessType.FIELD)
@NamedQueries({
		@NamedQuery( name = "MotoristaEntity.queryMan", 
					query = "from MotoristaEntity"),
		@NamedQuery( name = "MotoristaEntity.querySel", 
					query = " select   obj.id as id, "
									+ "obj.nome as nome, "
									+ "obj1.id as postoGraduacao_id, "
									+ "obj1.nome as postoGraduacao_nome, "
									+ "obj1.sigla as postoGraduacao_sigla, "
									+ "obj.identidade as identidade, "
									+ "obj.descricao as descricao "
								+ "from MotoristaEntity obj "
									+ "left outer join obj.postoGraduacao as obj1 "
								+ "order by obj.nome asc"),
		@NamedQuery( name = "MotoristaEntity.querySelLookup", 
					query = "select obj.id as id, "
				+ "obj.nome as nome, "
				+ "obj1.sigla as postoGraduacao_sigla "
				+ "from MotoristaEntity obj "
				+ "left outer join obj.postoGraduacao as obj1 "
				+ "where obj.id = ? " 
				+ "order by obj.id asc") })
public class MotoristaEntity extends Motorista {

	private static final long serialVersionUID = 1L;

	/*
	 * Construtor padrao
	 */
	public MotoristaEntity() {
	}

	@Override
	public String toString() {
		// return getNome();
		// FIXME Dá nullPointer ao se tentar retornar a sigla
		if (getPostoGraduacao() != null) {
			return getPostoGraduacao().getSigla() + " " + getNome();
		} else {
			return getNome();
		}
	}

}
